# 定义编译器和编译选项
CC = arm-linux-gnueabihf-gcc
CFLAGS = -Wall -I./Carama -I./FIFO -I./LED -I./Socket -I./LCD -I/root/tools/libjpeg/jpeg/include -Wall -O2

# 定义源文件和对象文件
SRCS = User/main.c Carama/carama.c FIFO/fifo.c LED/led.c Socket/scoket_thread.c LCD/lcd.c
OBJS = $(SRCS:%.c=build/%.o)

# 链接选项
LDFLAGS = -L/root/tools/libjpeg/jpeg/lib -ljpeg -lpthread -lrt

# 定义目标文件
TARGET = build/user_program

# 默认目标
all: build $(TARGET)

# 创建 build 目录
build:
	mkdir -p build/User build/Carama build/FIFO build/LED build/Socket build/LCD

# 链接对象文件生成可执行文件
$(TARGET): $(OBJS)
	$(CC) $(OBJS) $(LDFLAGS) -o $(TARGET)

# 编译源文件生成对象文件
build/%.o: %.c | build
	$(CC) $(CFLAGS) -c $< -o $@

# 清理生成的文件
clean:
	rm -rf build

.PHONY: all clean build